<script setup>
import MyNav from "../../../components/MyNav.vue";
import MyHead from "../../../components/MyHead.vue";
import MyTable from "../../../components/MyTable.vue";
import MyPager from "../../../components/MyPager.vue";
import { onMounted, reactive, ref } from "vue";
import { deleteApi, deleteBatchApi, pageApi } from "../../../api/axios.js";
import { myPage } from "../../../util/request.js";
import { isNotEmpty, isNotNull } from "../../../util/index.js";
import {notYet} from "../../../util/index.js";
import {MINIO_COURSE_COVER} from "../../../const/index.js";
// 路径导航
const navItems = [
  { icon: 'cart', label: '订单管理' },
  { icon: 'Flag', label: '购物车列表' },
];

// 页面头
const headItems = [
  { type: 'ipt', span: 5, placeholder: '按课程标题搜索', callback: pageLikeTitle },
];

// 表格列
const columns = [
  { label: '用户账号', prop: 'username', width: 120 },
  { label: '课程ID', prop: 'fkCourseId', width: 120 },
  { label: '课程标题', prop: 'courseTitle', type: 'title' },
  { label: '封面图', prop: 'courseCover', 'type': 'img', minio: MINIO_COURSE_COVER, width: 120},
  { label: '课程单价(元)', prop: 'coursePrice', type: 'title' },
];


// 表格行 + 分页 + 菜单标题
let records = ref([]);
let pageInfo = reactive({ pageNum: 1, pageSize: 5, callback: page });
let courseTitle = ref('');

// 分页查询
async function page(pageNum = pageInfo['pageNum'], pageSize = pageInfo['pageSize']) {
  let config = {
    records, pageInfo,
    api: pageApi,
    params: { pageNum, pageSize, pid: 0 },
    args: { module: 'cart' },
  };
  if (isNotEmpty(courseTitle.value)) config['params']['courseTitle'] = courseTitle.value;
  await myPage(config);
}

// 按菜单标题模糊查询
function pageLikeTitle(val) {
  if (isNotNull(val) || courseTitle.value) {
    courseTitle.value = val;
    page();
  }
}

// 查询子菜单


onMounted(() => page());
</script>


<template v-if="records">
  <my-nav :items="navItems"/>
  <my-head :items="headItems"/>
  <my-table module="cart"
            insert-page="/CartInsert"
            update-page="/CartUpdate"
            :delete-api="deleteApi"
            :delete-batch-api="deleteBatchApi"
            :delete-callback="page"
            :excel-api="notYet"
            :records="records"
            :columns="columns"/>
  <my-pager :page-info="pageInfo"/>
</template>

<style scoped lang="scss">

</style>